import 'dart:io';

import 'package:chat_app_project/components/video_viewer_page.dart';
import 'package:chat_app_project/models/msg.dart';
import 'package:flutter/material.dart';
import 'package:wukongimfluttersdk/model/wk_video_content.dart';
import 'package:wukongimfluttersdk/type/const.dart';

import '../../../constants.dart';
import '../../../models/const.dart';

class VideoMessage extends StatelessWidget {
  const VideoMessage({super.key, required this.message});
  final UIMsg message;

  double getMin(double b,BuildContext context){
    var a = MediaQuery.of(context).size.width * 0.45;
    if(a > b){
      return b;
    }
    return a;
  }

  @override
  Widget build(BuildContext context) {
    var wkMsg = message.wkMsg;
    var content = wkMsg.messageContent as WKVideoContent;
    var isSender = wkMsg.fromUID == UserInfo.uid;
    return SizedBox(
        width: getMin(content.width.toDouble(), context),
        child: AspectRatio(
          aspectRatio: 0.6,
          child: GestureDetector(
            onTap: () {
              Navigator.of(context).push(MaterialPageRoute(
                  builder: (context) =>
                      VideoViewerPage(url: content.url)));
            },
            child:  Stack(
              alignment: Alignment.center,
              children: [
                ClipRRect(
                    borderRadius: BorderRadius.circular(8),
                    child:  wkMsg.status == WKSendMsgResult.sendLoading
                        ? Image.file(File(content.coverLocalPath))
                        : Image.network(
                      content.cover,
                      // width: content.width.toDouble() ,
                      // height: content.height.toDouble(),
                      // fit: BoxFit.contain,
                    )
                ),
                Container(
                  height: 25,
                  width: 25,
                  decoration: const BoxDecoration(
                    shape: BoxShape.circle,
                    color: kPrimaryColor,
                  ),
                  child: const Icon(
                    Icons.play_arrow,
                    size: 16,
                    color: Colors.white,
                  ),
                ),
              ],
            ),
          ),
        ));
  }
}
